//
//  HomeTableViewController.m
//  随拍
//
//  Created by lanou3g on 16/1/18.
//  Copyright © 2016年 Ashoka. All rights reserved.
//

#import "HomeTableViewController.h"
#import "Shufflingfigure.h"
#import "HomeTableViewCell.h"

#import "PartTableViewController.h"

#import "HomeManager.h"
#import "HomeModel.h"

#import "UIImageView+WebCache.h"

#import "RootViewController.h"



@interface HomeTableViewController ()<ShufflingfigureDelegate>

@end

@implementation HomeTableViewController


NSString *identfier = @"cell";
- (void)viewDidLoad {
    [super viewDidLoad];
    
    
    
    
    
    [HomeManager sharedHomeManager].updateUI = ^(){
        [self.tableView reloadData];
        

        
    };
    
    
  
    
    
//            [self addShuffling:self.tableView];

    
    self.tableView = [[UITableView alloc] initWithFrame:[UIScreen mainScreen].bounds style:UITableViewStylePlain];
    
    [self.tableView registerClass:[HomeTableViewCell class] forCellReuseIdentifier:identfier];
    
    
    
    
    
}

#pragma mark addshuffling

//-(void)addShuffling:(UITableView *)tableView{
//    
// 
//}


#pragma mark shufflingfifure

-(void)shufflingfigureDidshuffing:(Shufflingfigure *)shuffingFigure atIndex:(NSUInteger)index{
  
}


-(void)tableView:(UITableView *)tableView willDisplayHeaderView:(UIView *)view forSection:(NSInteger)section{
    
    NSMutableArray *imagesArray = [NSMutableArray arrayWithCapacity:4];
    
    for ( int i = 1; i < 5; i++) {
        
//        HomeModel *manger = [HomeManager sharedHomeManager].dataArray[section];
        
        UIImageView *img = [[UIImageView alloc] init];
        
//        [img sd_setImageWithURL:[NSURL URLWithString:manger.image_url] placeholderImage:[UIImage imageNamed:@"1.jpg"]];
        
        
        [imagesArray addObject:img.image];
        
        
    }
    
    
    Shufflingfigure *shuffling = [[Shufflingfigure alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 200)];
    
    shuffling.imgArray = imagesArray;
    
    
    shuffling.delegate = self;
    
    self.tableView.tableHeaderView = shuffling;
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  
    return [HomeManager sharedHomeManager].dataArray.count;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    HomeTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identfier forIndexPath:indexPath];
    
    
   HomeModel *homeModel = [HomeManager sharedHomeManager].dataArray[indexPath.row];
    

    
    [cell.homeImg sd_setImageWithURL:[NSURL URLWithString:homeModel.image_url] placeholderImage:[UIImage imageNamed:@"1.jpg"]];

    
//    cell.hometitle.text = homeModel.text;
    
    return cell;
}



-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 211;
}


-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    PartTableViewController *part = [[PartTableViewController alloc] init];

    
//    HomeModel *homeModel = [HomeManager sharedHomeManager].dataArray [indexPath.row];
    RootViewController *NVR = [[RootViewController alloc] initWithRootViewController:part];
    
    
    NVR = (RootViewController *)self.navigationController;
    
   self.navigationController.navigationBar.translucent = YES;

    
    [NVR pushViewController:part animated:YES];
    
    
    
}

/*
// Override to support conditional editing of the table view.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the specified item to be editable.
    return YES;
}
*/

/*
// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        // Delete the row from the data source
        [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
    } else if (editingStyle == UITableViewCellEditingStyleInsert) {
        // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
    }   
}
*/

/*
// Override to support rearranging the table view.
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
}
*/

/*
// Override to support conditional rearranging of the table view.
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the item to be re-orderable.
    return YES;
}
*/

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
